package com.grq.mis.validate;

import com.grq.mis.entity.Notice;
import com.grq.mis.exception.BusinessException;
import com.grq.mis.exception.ResultEnum;
import org.springframework.util.StringUtils;

public class NoticeValidate {

    public static void add(Notice notice) {

        if (StringUtils.isEmpty(notice.getTitle())) {
            throw new BusinessException(ResultEnum.PARAM_ERROR, "标题不能为空");
        }
        if (notice.getTitle().length() > 50) {
            throw new BusinessException(ResultEnum.PARAM_ERROR, "标题最多为50字");
        }

        if (StringUtils.isEmpty(notice.getContent())) {
            throw new BusinessException(ResultEnum.PARAM_ERROR, "内容不能为空");
        }
        if (notice.getContent().length() > 500) {
            throw new BusinessException(ResultEnum.PARAM_ERROR, "内容最多为500字");
        }

        if (notice.getIsTip() == null){
            throw new BusinessException(ResultEnum.PARAM_ERROR, "强制弹出选项不能为空");
        }

    }

    public static void update(Notice notice) {

        if (notice.getId() == null){
            throw new BusinessException(ResultEnum.PARAM_ERROR, "消息通知id不能为空");
        }

        if (StringUtils.isEmpty(notice.getTitle())) {
            throw new BusinessException(ResultEnum.PARAM_ERROR, "标题不能为空");
        }
        if (notice.getTitle().length() > 50) {
            throw new BusinessException(ResultEnum.PARAM_ERROR, "标题最多为50字");
        }

        if (StringUtils.isEmpty(notice.getContent())) {
            throw new BusinessException(ResultEnum.PARAM_ERROR, "内容不能为空");
        }
        if (notice.getContent().length() > 500) {
            throw new BusinessException(ResultEnum.PARAM_ERROR, "内容最多为500字");
        }

        if (notice.getIsTip() == null){
            throw new BusinessException(ResultEnum.PARAM_ERROR, "强制弹出选项不能为空");
        }

        if (notice.getIsDisable() == null){
            throw new BusinessException(ResultEnum.PARAM_ERROR, "消息通知状态不能为空");
        }

    }
}
